package com.cans.lightning.business.lowcode.manager.form.loader.formBean;

import com.cans.lightning.business.lowcode.manager.form.bean.AppFormBean;
import com.cans.lightning.business.lowcode.manager.form.bean.FormFieldBean;
import com.cans.lightning.business.lowcode.manager.form.bean.TableBean;
import com.cans.lightning.business.lowcode.manager.form.loader.AbstractBeanLoader;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * FormBean 加载结束
 *
 * @author cans
 * @date 2023/11/29
 **/
@Component
public class FormBeanEndLoader extends AbstractBeanLoader<AppFormBean> {

    @Override
    public AppFormBean loadOne(AppFormBean appFormBean) {
        Map<String, FormFieldBean> res = Maps.newHashMap();
        List<TableBean> allTableBean = appFormBean.getAllTableBean();
        for (TableBean tableBean : allTableBean) {
            for (FormFieldBean formFieldBean : tableBean.getFieldList()) {
                formFieldBean.setTableId(tableBean.getId());
                res.put(formFieldBean.getDbFieldName(), formFieldBean);
            }
        }
        appFormBean.setFieldMap(res);
        return appFormBean;
    }

}
